package com.yn.pet.web.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yn.pet.bus.dao.LocationRealtimeDao;


import com.yn.pet.bus.entity.LocationRealtime;
import com.yn.pet.web.service.LocationRealtimeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 实时定位信息表(LocationRealtime)表服务实现类
 *
 * @author makejava
 * @since 2025-07-09 12:00:47
 */
@Service("locationRealtimeService")
@RequiredArgsConstructor
public class LocationRealtimeServiceImpl extends ServiceImpl<LocationRealtimeDao, LocationRealtime> implements LocationRealtimeService {

    /**
     * 查询实时信息定位列表_某设备的最新定位信息
     *
     * @param deviceId 设备ID
     * @return 实时信息定位列表_某设备的最新定位信息
     */
    @Override
    public LocationRealtime getLatestLocationByDeviceId(Long deviceId) {
        if (deviceId == null) {
            return null;
        }
        LambdaQueryWrapper<LocationRealtime> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(LocationRealtime::getDeviceId, deviceId)
                .orderByDesc(LocationRealtime::getCreateTime).last("limit 1");
        return this.getOne(queryWrapper);
    }

}

